package com.tuzhi.util;

import com.alibaba.fastjson2.JSONObject;

/**
 * fastjson2的工具类
 */
public class Fastjson2Util {

    /**
     * 直接查找深层的值，path的地址使用“:”分开
     * @param jsonObject
     * @param path
     * @param c
     * @return
     * @param <T>
     */
    public static <T> T find (JSONObject jsonObject, String path, Class<T> c) {
        if (jsonObject != null && StringTzUtil.isNotBlank(path)) {
            JSONObject tmpJson = jsonObject;
            String[] paths = path.split(":");
            for (int i = 0; i < paths.length; i++) {
                if (i == paths.length - 1) {
                    //最后节点
                    return tmpJson.getObject(paths[i], c);
                } else {
                    tmpJson = tmpJson.getJSONObject(paths[i]);
                }
            }

        }
        return null;
    }

}
